package com.atguigu.zhxy.controller;

import com.atguigu.zhxy.pojo.Clazz;
import com.atguigu.zhxy.service.ClazzService;
import com.atguigu.zhxy.util.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Api(tags = "班级管理器")
@RestController
@RequestMapping("/sms/clazzController")
public class ClazzController {
    @Autowired
    private ClazzService clazzService ;
    @ApiOperation("根据年级名称模糊查询，带分页")
    @GetMapping("/getClazzsByOpr/{pageNum}/{pageSize}")
    public Result getClazzsByOpr(
            @ApiParam("分页查询的页码数")@PathVariable("pageNum") Integer pageNum,
            @ApiParam("分页查询的记录数")@PathVariable("pageSize") Integer pageSize,
            @ApiParam("查询条件")Clazz clazz
    ){
//        分页带条件查询
        Page<Clazz> page = new Page<>(pageNum, pageSize);
//        通过服务层
        IPage<Clazz> gradeIPage = clazzService.getClazzsByPN(page,clazz);
//        封装result对象并返回
        return Result.ok(gradeIPage) ;
    }

    @ApiOperation("增加或修改班级信息")
    @PostMapping("/saveOrUpdateClazz")
    public Result saveOrUpdateClazz(@ApiParam("Json格式的班级信息")@RequestBody Clazz clazz){
        clazzService.saveOrUpdate(clazz) ;
        return Result.ok() ;
    }
    @ApiOperation("删除班级信息")
    @DeleteMapping("/deleteClazz")
    public Result deleteClazz(@ApiParam("Json格式的班级id数组")@RequestBody ArrayList<Integer> idList){
        clazzService.removeByIds(idList) ;
        return Result.ok() ;
    }

    @ApiOperation("获取全部班级")
    @GetMapping("/getClazzs")
    public Result getClazzs(){
        List<Clazz> clazzList =  clazzService.getClazz();
        return Result.ok(clazzList);
    }


}
